package com.kechen.client.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Author 0xHertz
 * @Date: 2022/11/5 0005 10:29
 * @Description: 远程测试Search中的Controller
 **/

@RestController
public class TestSearchController {
    @Autowired
    private EurekaClient eurekaClient;

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/customer")
    public String customer(){
        //1. 通过eurekaClient获取到SEARCH服务的信息,false指关闭安全连接，就是不使用https
        InstanceInfo info = eurekaClient.getNextServerFromEureka("QF-SEARCH", false);

        //2. 获取到访问的地址
        String url = info.getHomePageUrl();
        System.out.println(url);

        //3. 通过restTemplate访问
        String result = restTemplate.getForObject( "http://QF-SEARCH/search", String.class);

        //4. 返回
        return result;
    }
}
